<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.List"%>
<%@page import="net.ideapad.data.Group"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

<html>
	<head>
		<title>IdeaPad - View Groups</title>
		<link rel="stylesheet" type="text/css" href="styles/main.css">
		<link rel="stylesheet" type="text/css" href="styles/buttons.css">
		<link rel="stylesheet" type="text/css" href="styles/currentbutton.css">
	</head>
	<body>
		<div class="header">
			<html:link action="/default">
				<img src="/IdeaPad/images/ideapad_logo.png" alt="logo" border="0" />
			</html:link>
			<%
				if (session.getAttribute("username") == null || session.getAttribute("username") == "") {
			%>
			<html:link page="/form/login.jsp" styleClass="menubuttons">Login</html:link>
			<html:link page="/form/registerUser.jsp" styleClass="menubuttons">Register</html:link>
			<%
				} else {
			%>
			Hello
			<%=session.getAttribute("username").toString()%>
			<html:link action="viewGroups" styleClass="currentbutton">Groups</html:link>
			<html:link action="manageGroups" styleClass="menubuttons">Manage Groups</html:link>
			<html:link page="/form/editUserSettings.jsp" styleClass="menubuttons">Settings</html:link>
			<html:link action="logout" styleClass="menubuttons">Logout</html:link>
			<%
				}
			%>
		</div>
		<h1>
			Top Level Groups
		</h1>
		<table border="1">
			<tr>
				<td>
					Group ID
				</td>
				<td>
					Group Name
				</td>
			</tr>

			<logic:notEmpty name="TopGroups" scope="request">
				<logic:iterate name="TopGroups" id="group" scope="request">
					<tr>
						<td>
							<bean:write name="group" property="groupId" />
						</td>
						<td>
							<html:link action="viewGroup">
								<bean:write name="group" property="groupName" />
								<html:param name="groupID"
									value="<%= ((Group) group).getGroupId().toString() %>" />
							</html:link>
						</td>
					</tr>
				</logic:iterate>
			</logic:notEmpty>
		</table>

		<h1>
			All Other Groups
		</h1>
		<table border="1">
			<tr>
				<td>
					Group ID
				</td>
				<td>
					Group Name
				</td>
				<td>
					Parent Group
				</td>
			</tr>

			<logic:notEmpty name="OtherGroups" scope="request">
				<logic:iterate name="OtherGroups" id="group" scope="request">
					<tr>
						<td>
							<bean:write name="group" property="groupId" />
						</td>
						<td>
							<html:link action="viewGroup">
								<bean:write name="group" property="groupName" />
								<bean:define id="groupID" name="group" property="groupId" />
								<html:param name="groupID" value="<%= groupID.toString() %>" />
							</html:link>
						</td>
						<td>
							<logic:empty name="group" property="parentGroup">NONE</logic:empty>
							<logic:notEmpty name="group" property="parentGroup">
								<bean:write name="group" property="parentGroup.groupName" />
							</logic:notEmpty>
						</td>
					</tr>
				</logic:iterate>
			</logic:notEmpty>
		</table>

		<html:link page="/form/createGroup.jsp">
				Create a New Group
		</html:link>
	</body>
</html>

